package entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlTransient;
import valueObject.ProfessorVO;
import valueObject.UniversityVO;

/**
 *
 * @author David
 */
@Entity
@Table(name = "university")
@NamedQueries({
    @NamedQuery(name = "University.findAll", query = "SELECT u FROM University u")
    })
public class University implements Serializable, JPAEntity<UniversityVO> {
    @Id
    @Basic(optional = false)
    @Column(name = "universityUser")
    private String universityUser;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Column(name = "address")
    private String address;
    @Column(name = "phoneNumber")
    private String phoneNumber;
    @Column(name = "type")
    private String type;
    @Column(name = "web")
    private String web;
    @Basic(optional = false)
    @Column(name = "joinDate")
    @Temporal(TemporalType.DATE)
    private Date joinDate;
    @Lob
    @Column(name = "description")
    private String description;
    @Column(name = "location")
    private String location;
    @Lob
    @Column(name = "image")
    private byte[] image;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "universityuserUniversity")
    private Collection<Professor> professorCollection;

    public University() {
    }

    public University(String universityUser) {
        this.universityUser = universityUser;
    }

    public University(String universityUser, String name, Date joinDate) {
        this.universityUser = universityUser;
        this.name = name;
        this.joinDate = joinDate;
    }

    public String getUniversityUser() {
        return universityUser;
    }

    public void setUniversityUser(String universityUser) {
        this.universityUser = universityUser;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getWeb() {
        return web;
    }

    public void setWeb(String web) {
        this.web = web;
    }

    public Date getJoinDate() {
        return joinDate;
    }

    public void setJoinDate(Date joinDate) {
        this.joinDate = joinDate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getLocation() {
        return location;
    }

    public void setLocation(String location) {
        this.location = location;
    }

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }

    @XmlTransient
    public Collection<Professor> getProfessorCollection() {
        return professorCollection;
    }

    public void setProfessorCollection(Collection<Professor> professorCollection) {
        this.professorCollection = professorCollection;
    }

    @Override
    public UniversityVO toValueObject() {
        UniversityVO universityVO = new UniversityVO();
        universityVO.setAddress(address);
        universityVO.setDescription(description);
        universityVO.setImage(image);
        universityVO.setJoinDate(joinDate);
        universityVO.setLocation(location);
        universityVO.setName(name);
        universityVO.setPhoneNumber(phoneNumber);
        ArrayList<ProfessorVO> professorVOs = new ArrayList<ProfessorVO>();
        /*if(professorCollection != null){
            for(Professor p : professorCollection){
                professorVOs.add(p.toValueObject());
            }
        }*/
        universityVO.setProfessors(professorVOs);
        universityVO.setType(type);
        universityVO.setUserName(universityUser);
        universityVO.setWeb(web);
        return universityVO;
    }

}